package com.lagou.rpc.provider;

import com.lagou.rpc.provider.zkUtil.ZKClientUtil;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Description: TODO
 * @Author 50705 2021/11/19
 **/

@Controller("/close")
public class StopServerController implements ApplicationContextAware {

    private ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    @GetMapping
    public String shutDownContext() {
        ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) context;
        ZKClientUtil.getInstance().close();
        System.out.println("==========ZooKeeper session close.==========");
        ctx.close();
        System.out.println("==========ApplicationContext close.==========");
        return "context is shutdown";
    }
}
